import {post,put,fetch,del} from './http'

// 修改用户信息
export const userUpdate = function (data) {
    return new Promise((resolve, reject) => {
        put('/rubbish-server/user/update/'+data.id, data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
export const getUserInfo = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/user'+data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 

// 登录
export const login = function (data) {
    return new Promise((resolve, reject) => {
        post('/rubbish-server/login/login', data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
// 注册
export const register = function (data) {
    return new Promise((resolve, reject) => {
        post('/rubbish-server/login/register', data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

// 获取标签
export const getTag = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/tag/all').then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 

// 超管使用
// 修改admin信息
export const adminUpdate = function (data) {
  return new Promise((resolve, reject) => {
      put('/rubbish-server/admin/dete', data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 获取用户信息
export const getUserList = function (data) {
  return new Promise((resolve, reject) => {
    post('/rubbish-server/admin/page',data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 管理员登录
export const adminLogin = function (data) {
  return new Promise((resolve, reject) => {
    post('/rubbish-server/admin/login',data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 创建用户
export const createUser = function (data) {
  return new Promise((resolve, reject) => {
    post('/rubbish-server/admin/create',data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 获取用户信息
export const adminGetUserInfo = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/admin'+data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 删除
export const admindelUser = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/admin/delete'+data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 批量删除
export const adminDelUserBatch = function (data) {
    return new Promise((resolve, reject) => {
      del('/rubbish-server/admin/delete'+data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 创建用户
export const plantRubbish = function (data) {
  return new Promise((resolve, reject) => {
    post('/plant',data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
}  
// 查询用户分类数据
export const rubbishQuery = function (data) {
  return new Promise((resolve, reject) => {
    post('/rubbish-server/rubbish/query',data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 查询积分奖品
export const awardQuery = function (data) {
  return new Promise((resolve, reject) => {
    post('/rubbish-server/award/query',data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 兑换积分奖品
export const awardBuy = function (data) {
  return new Promise((resolve, reject) => {
    put(`/rubbish-server/award/buy/${data.userId}/${data.awardId}`,data).then(res =>{
          resolve(res)
      }).catch(err => {
          reject(err)
      })
  })
} 
// 获取积分
export const rubbishPoints = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/rubbish/points/'+ data.userId).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 获取文章
export const articleAll = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/article/all').then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 获取文章
export const articlePage = function (data) {
    return new Promise((resolve, reject) => {
      post('/rubbish-server/article/page',data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 获取文章
export const getAwardByUser = function (data) {
    return new Promise((resolve, reject) => {
      post('/rubbish-server/award/get/user/award',data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
} 
// 获取文章
export const getStatistics = function (data) {
    return new Promise((resolve, reject) => {
      fetch('/rubbish-server/rubbish/statistics/'+ data).then(res =>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}